var http = require('http')
var fs = require('fs')
var template = require('art-template')

http.createServer(function (res,rep) {
    fs.readdir('./public',function (err,files) {
        if (err){
            return rep.end('404 not found')
        }
        fs.readFile('./apche_template.html',function (err,data) {
            if (err){
                return rep.end('404 not found')
            }
            var html = template.render(data.toString(),{
                title:'动态读取apache目录',
                files:files
            })
            rep.end(html)
        })
    })
}).listen(3000,function () {
    console.log('server is running')
})